<?php
require_once 'PmsDb.php';
define("LOG_PATH", "/alidata/log/fdn/fdn.log");
//日志
function logResult($string, $path) {
	$fp = fopen($path, "a");
	flock($fp, LOCK_EX);
	fwrite($fp, "执行日期：" . strftime("%Y-%m-%d %H:%M:%S", time()) . "\n" . $string . "\n");
	flock($fp, LOCK_UN);
	fclose($fp);
}
function updateOrder($orderId, $status,$remark="") {
	try {
		global $pmsDb;
		$sql = "update t_fdn_order set status = ?,updated_at=?,remark = ? where order_id = ?";
		$result = $pmsDb->pdo->prepare ( $sql );
		$result->bindValue ( 1, $status );
		$result->bindValue ( 2, date("Y-m-d H:i:s") );
		$result->bindValue ( 3, $remark );
		$result->bindValue ( 4, $orderId );
		$result->execute ();
	} catch ( PDOException $e ) {
		return false;
	}
	return true;
}
$day = date('Y-m-d');
$data = @file_get_contents('php://input');
$jsonObj = json_decode($data,true);
$orderId = $jsonObj ['orderId'];
$resultCode = $jsonObj ['resultCode'];
$cpOrderNo = $jsonObj ['cpOrderNo'];
$transNo = $jsonObj ['transNo'];
logResult($day."#".json_encode($_REQUEST)."RAW:$data",LOG_PATH);
$pmsDb = new PmsDb ( 'fdn' );
if($resultCode==10100){
	$re = updateOrder($orderId,1);
	if($re){
		echo "ok";	
        die;
	}
}else{
	$re = updateOrder($orderId,2,$resultCode);
}
echo "no";	
?>
